import { constantRoutes, asyncRoutes } from '../../router/index'

const state = {
  routes: constantRoutes
}

const mutations = {
  SET_ROUTES (state, payload) {
    state.routes = [...constantRoutes, ...payload]
  }
}

const actions = {
  setRoute (context, menus) {
    console.log(asyncRoutes)
    const myRoute = asyncRoutes.filter(item => {
      return menus.map(i => '/' + i).includes(item.path)
    })
    context.commit('SET_ROUTES', myRoute)

    return myRoute
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
